#include "../../lv_examples.h"
#if LV_USE_IMGBTN && LV_BUILD_EXAMPLES

void lv_example_imgbtn_1(void)
{
    #define myW  120
    LV_IMG_DECLARE(imgbtn_left);
    LV_IMG_DECLARE(imgbtn_right);
    LV_IMG_DECLARE(imgbtn_mid);

    /*Create a transition animation on width transformation and recolor.*/
    static lv_style_prop_t tr_prop[] = {LV_STYLE_TRANSFORM_WIDTH, LV_STYLE_IMG_RECOLOR_OPA, 0};
    static lv_style_transition_dsc_t tr;
    lv_style_transition_dsc_init(&tr, tr_prop, lv_anim_path_linear, 200, 0, NULL);

    static lv_style_t style_def;
    lv_style_init(&style_def);
    lv_style_set_width(&style_def, myW);
    // lv_style_set_size(&style_def, 200, 100);
    lv_style_set_text_color(&style_def, lv_color_make(0, 0xff, 0));//@@ RGB-GREEN
    // lv_style_set_text_color(&style_def, lv_color_white());
    lv_style_set_transition(&style_def, &tr);

    /*Darken the button when pressed and make it wider*/
    static lv_style_t style_pr;
    lv_style_init(&style_pr);
    lv_style_set_width(&style_pr, myW);
    // lv_style_set_size(&style_pr, 200, 100);
    // lv_style_set_img_recolor_opa(&style_pr, LV_OPA_20); // 按下后的颜色变化小一点
    lv_style_set_img_recolor_opa(&style_pr, LV_OPA_30);
    lv_style_set_img_recolor(&style_pr, lv_color_black());
    lv_style_set_transform_width(&style_pr, 2);
    // lv_style_set_transform_width(&style_pr, 20);

    /*Create an image button*/
    lv_obj_t * imgbtn1 = lv_imgbtn_create(lv_scr_act());
    lv_imgbtn_set_src(imgbtn1, LV_IMGBTN_STATE_RELEASED, &imgbtn_left, &imgbtn_mid, &imgbtn_right);
    lv_obj_add_style(imgbtn1, &style_def, 0);
    lv_obj_add_style(imgbtn1, &style_pr, LV_STATE_PRESSED);

    lv_obj_align(imgbtn1, LV_ALIGN_CENTER, 0, 0);

    /*Create a label on the image button*/
    lv_obj_t * label = lv_label_create(imgbtn1);
    lv_label_set_text(label, "828.9");  //@@2024-02-13 20:11:54
    lv_obj_set_style_text_font(label, &lv_font_montserrat_32, 0);
    // lv_label_set_text(label, "Button");
    lv_obj_align(label, LV_ALIGN_CENTER, 0, -4);


    //@@2024-02-13 20:34:53 按键的宽度在哪里设置??
    // 通过lv_style_set_size()可人为设置其w,h, 但与左中右的img会有冲突
    // 最好是只设置宽度: lv_style_set_width()
    // lv_style_set_size(&style_pr, 200, 100);
    // 以下通过整体放大处理: 效果不错哦
    lv_obj_set_style_transform_zoom(imgbtn1, 256*3, 0);   /*3x*/ //@@ 2024-02-18 13:42:49
}

#endif
